<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\index\controller;
use app\common\controller\HomeBase;
use think\Db;
use think\Request;

/**
 * Description of Analysis
 *
 * @author maylor
 */
class Research extends HomeBase{
    //put your code here
    
    protected function _initialize() {
        parent::_initialize();
        $this->assign('this_controller','industryresearch');
    }


    public function index(Request $request) {
        $cates = Db::name('category')->field('id,name')->where(['id'=>['in',[4,5]]])->select();
        foreach($cates as $key=>$v) {
            $lists = Db::name('article')->field('id,title,create_time,publish_time')->where(['cid'=>$v['id'],'status'=>1])->order('id desc')->limit(50)->select();
            $cates[$key]['lists'] = $lists;
        }
        $this->assign('cates',$cates);
        return $this->fetch();
    }
    
    public function detail($id) {
        $data = Db::name('article')->where(['cid'=>['in',[4,5]],'status'=>1,'id'=>$id])->find();

        if(!empty($data)) {
            $lastid = Db::name('article')->where(['cid'=>['in',[4,5]],'status'=>1,'id'=>['<',$id]])->order('id desc')->value('id');
            $nextid = Db::name('article')->where(['cid'=>['in',[4,5]],'status'=>1,'id'=>['>',$id]])->order('id asc')->value('id');
        }else {
           return $this->error();
        }
        $this->assign('lastid',$lastid);
        $this->assign('nextid',$nextid);
        $this->assign('data',$data);
        return $this->fetch();
    }
}
